import { Form, Modal, Select } from 'antd';

const AddCourse = ({
  open,
  onCreate,
  onCancel,
  collInfor,
  additionalInfor,
  curriculums
}) => {
  const [form] = Form.useForm();

  const Items = [
    { name: "fd_teacNum", label: "教师", rules: {}, disable: true, options: additionalInfor.teacher },
    { name: "fd_classRoomNum", label: "地点", rules: {}, disable: false, options: additionalInfor.classroom },
    { name: "fd_claNum", label: "班级", rules: {}, disable: false, options: additionalInfor.classes },
    { name: "fd_curriculumNum", label: "课程", rules: {}, disable: false, options: curriculums },
  ]
  return (
    <Modal
      destroyOnClose
      width={511}
      open={open}
      okText={collInfor?.fd_id ? "修改" : "添加"}
      cancelText="退出"
      onCancel={onCancel}
      onOk={() => {
        form
          .validateFields()
          .then((values) => {
            form.resetFields();
            onCreate({ ...collInfor, ...values });
          })
          .catch((info) => {
            console.log('Validate Failed:', info);
          });
      }}
    >
      <Form
        preserve={false}
        form={form}
        layout="horizontal"
        name="form_in_modal"
        wrapperCol={{
          span: 12,
        }}
        className="updata-user-infor"
      >
        {
          Items.map((item) => {
            return (
              <Form.Item
                labelAlign='left'
                key={item.name}
                name={item.name}
                label={item.label}
                rules={[item.rules?.must]}
                initialValue={collInfor?.[item.name]}
                labelCol={{
                  offset: 1,
                  span: 5
                }}
                wrapperCol={{
                  span: 17,
                  offset: 0
                }}
              >
                <Select
                  showSearch
                  filterOption={(input, option) =>
                    (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
                  }
                  options={item.options}
                  disabled={item.disable}
                />
              </Form.Item>
            )
          })
        }
      </Form>
    </Modal>
  );
};
export default AddCourse